<?php
namespace app\admin\controller;
use app\admin\validate\UserValidate;
use app\admin\model\DiscountModel;
use think\facade\Request;
use think\Db;
/**
 * 卡卷控制器
 */
class Discount extends UserValidate{
    /**
     * 首页
     * @return \think\response\View
     */
        public function index(){
            $date = (new DiscountModel)->index();
            $this->assign('date', $date);
            return view();
        }

    /**
     * 添加卡卷
     */
        public function shopAdds(){
            $value = request::get();
           $result= (new DiscountModel)->dataVerification($value);
           if ($result === true){
               $this->success('新增成功');
           }
            $this->error($result);
        }
    /**
     * 指定用户
     */
        public function appointAdd(){
            $volume_id = request::get('volume_id');
            $id = request::get('id');
            if (!is_string($volume_id) && !is_string($id)){
                $this->error('缺少参数');
            }
            $uservolume = (new DiscountModel)->userAdd($volume_id,$id);
            $this->success('新增成功');
        }
    /**
     * 删除卡卷
     */
        public function appointdel(){
            $id = input('id');
            if ($id){
                $data = (new DiscountModel)->del($id);
                if ($data){
                    $this->success('删除成功');
                }
                $this->error('删除失败');
            }
            $this->error('缺少参数');
        }
    /**
     * 卡卷修改
     */
    public function appointRepairs(){
        $value = request::get();
        $result= (new DiscountModel)->dataVerifications($value);
        if ($result === true){
            $this->success('修改成功');
        }
        $this->error($result);
    }
    /**
     * 用户卡卷--展示
     */
        public function userCard(){
            $usercard = (new DiscountModel)->userCard();
            $this->assign('usercard', $usercard);
            return view();
        }
    /**
     * 用户卡卷--详情
     */
        public function userCards(){
            $id = input('id');
            $userid = (new DiscountModel)->userCards($id);
            if ($userid){
                $this->assign('userid', $userid);
                return view();
            }
            $this->error('该用户没有卷');
        }
        public function appointdels(){
            $id = input('id');
            $userid = (new DiscountModel)->appointdels($id);
            if ($userid){
                $this->success('删除成功');
            }
            $this->error('删除失败');
        }
    /**
     * 搜索
     * @return mixed
     * @return id  卡卷 id
     * @return mobile  手机号
     */
        public function search(){
            $mobile = request::get('mobile');
            $id = input('id');
            $user = (new DiscountModel)->userSearch($mobile);
            $this->assign('volume_id', $id);
            $this->assign('userletter', $user);
            return $this->fetch('discount/appoint');
        }

    /**
     * 指定用户--渲染
     * @return \think\response\View
     * @return id  卡卷 id
     */
    public function appoint(){
        $id = input('id');
        $userletter = (new DiscountModel)->userList();
        $this->assign('volume_id', $id);
        $this->assign('userletter', $userletter);
        return view();
    }
    /**
     * 添加卡卷--渲染页面
     * @return \think\response\View
     */
    public function shopAdd(){
        $list = (new DiscountModel)->addVolume();
        $this->assign('list', $list);
        return view();
    }


    /**
     * 修改--渲染
     * @return \think\response\View
     */
    public function appointRepair(){
        $volume = (new DiscountModel)->volumeRepair(input('id'));
        $this->assign('volume', $volume);
        return view();
    }

}